import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutterlib/common/net/dao_result.dart';
import 'package:flutterlib/common/style/font_awesome4_icons.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/navigator_utils.dart';
import 'package:flutterlib/widgets/bussiness/user_info_widget.dart';
import 'package:flutterlib/widgets/pull/nested/simple_pull_load_manger.dart';
import 'package:flutterlib/widgets/pull/nested/simple_pull_load_page_widget.dart';
import 'package:flutterlib/common/constants/constants.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:thrio/thrio.dart';

class NavList {
  NavList({
    this.imagePath,
    this.name = '',
    this.thiroPath = '',

  });

  String name;
  IconData imagePath;
  String thiroPath;

  static List<NavList> homeList = [
    NavList(
      imagePath: MIcon.message,
      name: "我的消息",
      thiroPath: '/native/ImPersonalMsgActivity'
    ),
    NavList(
      imagePath: AIcon.doc,
      name: "我的文章",
      thiroPath: '/post/mine'
    ),
    NavList(
      imagePath: MIcon.directions_bike,
      name: "我的兴趣",
      thiroPath: '/interest/mine'
    ),
    NavList(
      imagePath: MIcon.local_activity,
      name: "我的活动",
      thiroPath: '/activity/mine'
    ),
  ];
}

class Page extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return PageState();
  }
}

class PageState extends State<Page> with TickerProviderStateMixin {
  SimplePullLoadManger manger;

  @override
  void initState() {
    super.initState();

    manger = SimplePullLoadManger(
        getDataLogic: getDataLogic,
        renderItem: renderItem,
        renderHeader: renderHeader,
        enablePullDown: false,
        enablePullUp: false);
  }

  getDataLogic(int page) async {
    print(page);
    return new DataResult(NavList.homeList, true);
  }

  Widget renderItem(index, tabItem) {
    return Container(
      child: InkWell(
        splashColor: Colors.white.withOpacity(0.2),
        // highlightColor: Colors.transparent,
        // focusColor: Colors.transparent,
        onTap: () {
          ThrioNavigator.push(url: tabItem.thiroPath);
          // NavigatorUtils.NavigatorRouter(context, tabItem.navigateScreen);
        },
        child: Padding(
          padding: const EdgeInsets.fromLTRB(17.0, 17, 10, 17),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Icon(
                tabItem.imagePath,
                size: 14,
              ),
              SizedBox(
                width: 12,
              ),
              Expanded(
                  child: Text(
                tabItem.name,
                style: QuhuiConstant.minText,
              )),
              Icon(
                AIcon.right_open,
                size: 12,
              )
            ],
          ),
        ),
      ),
    );
    //提交
    // var post = pullLoadWidgetControl.dataList[index];
    // return InterestListItem(interest, onPressed: () {
    //   NavigatorUtils.NavigatorRouter(context, InterestDetailPage(interestId: interest.id,));
    // });
  }

  List<Widget> renderHeader(BuildContext context, bool innerBoxIsScrolled) {
    return <Widget>[
      SafeArea(
        child: Consumer<SettingsStore>(
          builder: (_, store, __) {
            return Observer(
              builder: (_) {
                final userEntity = store.userEntity;

                return Padding(
                  padding: const EdgeInsets.fromLTRB(15.0, 41, 0, 18.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      store.isLogin
                          ? UserInfoWidget(
                              image: userEntity.logo,
                              width: 50.w,
                              height: 50.h,
                              onPressed: () {
                                ///跳到用户信息绑定页面
                              })
                          : InkWell(
                              borderRadius: const BorderRadius.all(
                                Radius.circular(32.0),
                              ),
                              onTap: () {
                                NavigatorUtils.goLogin(context);
                              },
                              child: Icon(
                                AIcon.slideshare,
                                size: 50.w,
                                color: Colors.black,
                              ),
                            ),
                      SizedBox(
                        width: 20.w,
                      ),
                      SizedBox(
                        width: 200,
                        height: 50,
                        child: Align(
                          alignment: Alignment.topLeft,
                          child: store.isLogin
                              ? Text(
                                  userEntity?.userName,
                                  style: QuhuiConstant.middleTextBold,
                                )
                              : Text(
                                  "登录/注册",
                                  style: QuhuiConstant.middleTextBold,
                                ),
                        ),
                      ),
                    ],
                  ),
                );
              },
            );
          },
        ),
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        title: Text("设置"),
      ),
      backgroundColor: QuhuiColors.miWhite,
      body: SimplePullLoadWidget(
        pullLoadManger: manger,
      ),
    );
  }
}
